<template>
  <div>

    <div>
      异常单号
      <el-input v-model="exceptionId" placeholder="异常单号" style="width:280px"></el-input>
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;派车单号
      <el-input v-model="dispatchId" placeholder="派车单号" style="width:280px"></el-input>
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;异常类型
      <el-input v-model="exceptionType" placeholder="异常类型" style="width:280px"></el-input>
      <el-button type="primary" @click="search()">查询</el-button>
    </div>

    <br>
    <br>
    <br>
    <br>

    <template>
      <el-table
        :data="exbriefs"
        border
        style="width: 100%"
        @selection-change="handleSelectionChange">
        <el-table-column
          type="selection"
          width="55">
        </el-table-column>
        <el-table-column
          prop="exceptionId"
          label="异常单号"
          width="180"
          align="center">
        </el-table-column>
        <el-table-column
          prop="tTrack.dispatchId"
          label="派车单号"
          width="180"
          align="center">
        </el-table-column>
        <el-table-column
          prop="tException.feedbackTime"
          label="反馈时间"
          width="180"
          align="center">
        </el-table-column>
        <el-table-column
          prop="tException.exceptionType"
          label="异常类型"
          width="180"
          align="center">
        </el-table-column>
        <!--<el-table-column
          prop="progressId"
          label="处理进度"
          width="180"
          align="center">
          <el-select  v-model="progressId" placeholder="请选择" style="width: 120px" >
            <el-option v-for="item in progresses" :key="item.progressId" :label="item.name"
                       :value="item.progressId" style="width: 400px" @click.native="changeItem(item)">
            </el-option>
          </el-select>
        </el-table-column>-->

        <el-table-column  prop="tProgress.name" label=处理进度 :width="180">
          <template slot-scope="scope">
            <el-select :ref="scope.row.id"  v-model="scope.row.progressId" @change="changeProgress(scope.row)">
              <el-option v-for="item in scope.row.progresses" :label="item.name" :value="item.progressId" :key="item.progressId"></el-option>
            </el-select>
          </template>
        </el-table-column>

        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="danger"
              @click="addManage(scope.$index, scope.row)">添加管理
            </el-button>
            <el-button
              size="mini"
              type="danger"
              @click="updateManage(scope.$index, scope.row)">编辑管理
            </el-button>
          </template>
        </el-table-column>
      </el-table>
    </template>

    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="currentPage"
      :page-sizes="pageSizes"
      :page-size="pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total">
    </el-pagination>

    <el-dialog title="异常登记" :visible.sync="dialogVisible" width="80%" :before-close="handleClose">
      <br>
      <br>
      <span>派车单信息</span>
      <br>
      <br>
      <el-table :data="Ttrack">
        <el-table-column property="dispatchId" label="派车单号" width="150"></el-table-column>
        <el-table-column property="logistics.route" label="路线" width="200"></el-table-column>
        <el-table-column property="logistics.appointedTime" label="指派时间" width="200"></el-table-column>
        <el-table-column property="logistics.cartypeName" label="车辆类型" width="200"></el-table-column>
        <el-table-column property="logistics.carrierName" label="承运商" width="200"></el-table-column>
        <el-table-column property="logistics.carPlate" label="车辆" width="200"></el-table-column>
        <el-table-column property="logistics.driverName" label="司机" width="200"></el-table-column>
        <el-table-column property="logistics.nodeCurrent" label="节点" width="200"></el-table-column>
      </el-table>
      <br>
      <hr>
      <br>
      <el-form   label-width="80px" :model="Texception" ref="Texception" aria-readonly="true">
        <br>
        <br>
        <span>异常登记</span>
        <br>
        <br>
        <el-row>
          <el-col :span="12">
            <el-form-item label="当前节点"  style="width: 400px" prop="location" >
              <el-input v-model="Texception.location" :disabled="edit"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="事故类型"  style="width: 400px" prop="exceptionType" >
              <el-input v-model="Texception.exceptionType":disabled="edit"></el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="反馈者" style="width: 400px" prop="feedbacker" >
              <el-input v-model="Texception.feedbacker" :disabled="edit"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="发现时间" style="width: 400px" prop="findTime">
              <el-date-picker value-format="yyyy-MM-dd HH:mm:ss" v-model="Texception.findTime" type="datetime" :disabled="edit"></el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="反馈方式" style="width: 400px" prop="feedbackway">
              <el-input v-model="Texception.feedbackway" :disabled="edit"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="反馈时间" style="width: 400px" prop="feedbackTime">
              <el-date-picker value-format="yyyy-MM-dd HH:mm:ss" v-model="Texception.feedbackTime" type="datetime" :disabled="edit"></el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
        <el-form-item label="异常说明" style="width: 500px" prop="introduction">
          <el-input type="textarea"  v-model="Texception.introduction" :disabled="edit"></el-input>
        </el-form-item>
      </el-form>
      <br>
      <hr>
      <br>
      <br>
      <span>异常处理</span>
      <br>
      <br>
      <el-form   label-width="80px" :model="Texhandle" ref="Texhandle">

            <el-form-item label="异常影响"  style="width: 400px" prop="influence" >
              <el-input v-model="Texhandle.influence" ></el-input>
            </el-form-item>

        责任认定&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <el-select  v-model="Texhandle.liablesideId" placeholder="请选择" style="width: 320px">
        <el-option v-for="item in liableside" :key="item.liablesideId" :label="item.name"
                   :value="item.liablesideId" style="width: 400px">
        </el-option>
        </el-select>
        <br>
        <br>
            <el-form-item label="事故原因" style="width: 400px" prop="excause" >
              <el-input v-model="Texhandle.excause" ></el-input>
            </el-form-item>

            <el-form-item label="处理方式" style="width: 400px" prop="approach">
              <el-input v-model="Texhandle.approach" ></el-input>
            </el-form-item>

            <el-row>
            <el-col :span="12">
              <el-form-item label="赔偿客户金额" style="width: 500px" prop="penalty">
                <el-input type="textarea"  v-model="Texhandle.penalty" ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="承运商承担金额" style="width: 500px" prop="comafford">
                <el-input type="textarea"  v-model="Texhandle.comafford" ></el-input>
              </el-form-item>
            </el-col>
          </el-row>

      </el-form>

      <span slot="footer" class="dialog-footer">
					<el-button @click="dialogVisible = false,cancelUpData()">取 消</el-button>
					<el-button type="primary" @click="dialogVisible = false , addHdData()">提 交 处 理 记 录</el-button>
        <el-button type="primary" @click="dialogVisible = false , updateHdData()">编 辑 处 理 记 录</el-button>
				</span>
    </el-dialog>

  </div>
</template>

<script>
    export default {
        name: "exBrief",
      data(){
        return{
          exbriefs:[],
          exbrief:{
            exceptionId:"",
            tTrack:{
              dispatchId:"",
            },
            tException:{
              feedbackTime:"",
              exceptionType:"",
            },
            progressId:"",
            tProgress:{
              progressId: "",
              name:""
            },
            progresses:[]
          },
          currentPage: 1,
          pageSize: 2,
          total:0,
          pageSizes: [1, 2, 3, 4],
          Ttrack:[],
          dialogVisible:false,
          Texception:{
            location:"",
            exceptionType:"",
            feedbacker:"",
            findTime:"",
            feedbackway:"",
            feedbackTime:"",
            introduction:"",
            trackId:"",
          },
          edit: true,
          Texhandle:{
            influence:"",
            liablesideId:"",
            excause:"",
            approach:"",
            penalty:"",
            comafford:"",
            trackId:"",
          },
          liableside:[],
          exceptionId:"",
          dispatchId:"",
          exceptionType:"",
          /*progresses:[
            {1:"未处理"},
            {2:"处理中"},
            {3:"已处理"}
          ],*/
        }
      },
      methods: {

       /* src(progressId){
        let name= this.exbrief.progresses.get(progressId);
        },*/
        changeProgress(row){
            console.log(row);
        },
        search(){
        this.findAll(this.currentPage, this.pageSize,this.exceptionId,this.dispatchId,this.exceptionType)
        },
        updateHdData(){
          this.$http({
            method: "PUT",
            url: "http://localhost:8090/tExhandle",
            data: this.Texhandle
          }).then(resp => {
            this.Texhandle={
              influence:"",
              liableside:"",
              excause:"",
              approach:"",
              penalty:"",
              comafford:"",
              trackId:"",
            }
          })
        },
        addHdData(){
          this.$http({
            method: "POST",
            url: "http://localhost:8090/tExhandle",
            data: this.Texhandle
          }).then(resp => {
            this.Texhandle={
              influence:"",
              liableside:"",
              excause:"",
              approach:"",
              penalty:"",
              comafford:"",
              trackId:"",
            }
          })

        },
        findHdByTrackId(trackId) {
          this.$http({
            type: "GET",
            url: `http://localhost:8090/tExhandle/${trackId}`
          }).then(resp => {
            console.log(resp);
            console.log(resp.data);
            this.Texhandle = resp.data;
          })
        },
        cancelUpData(){
          this.Texhandle={
            influence:"",
              liableside:"",
              excause:"",
              approach:"",
              penalty:"",
              comafford:"",
              trackId:"",
          }
        },
        updateData(){
          this.$http({
            method: "PUT",
            url: "http://localhost:8090/tException",
            data: this.Texception
          }).then(resp => {
            this.Texception={
              location:"",
              exceptionType:"",
              feedbacker:"",
              findTime:"",
              feedbackway:"",
              feedbackTime:"",
              introduction:"",
              trackId:"",
            }
          })
        },
        addExData(){
          this.$http({
            method: "POST",
            url: "http://localhost:8090/tException",
            data: this.Texception
          }).then(resp => {
            this.Texception={
              location:"",
              exceptionType:"",
              feedbacker:"",
              findTime:"",
              feedbackway:"",
              feedbackTime:"",
              introduction:"",
              trackId:"",
            }
          })
        },
        findEByTrackId(trackId) {
          this.$http({
            type: "GET",
            url: `http://localhost:8090/tException/${trackId}`
          }).then(resp => {
            console.log(resp);
            console.log(resp.data);
            this.Texception = resp.data;
          })
        },
        handleClose(){
          this.dialogVisible=false;
        },
        findById(trackId) {
          this.$http({
            type: "GET",
            url: `http://localhost:8090/tTrack/${trackId}`
          }).then(resp => {
            console.log(resp);
            console.log(resp.data);
            this.Ttrack = [resp.data];         //饿了吗form的数据类型是对象，table的数据类型是数组，一个对象如何被table接收到？就是
          })
        },
        updateManage(index, row){
          this.dialogVisible=true;
          console.log(row.trackId);
          let trackId = row.trackId;
          this.findById(trackId);
          this.findEByTrackId(trackId);
          this.findHdByTrackId(trackId);


        },
        addManage(index, row){
          this.dialogVisible=true;
          console.log(row.trackId);
          let trackId = row.trackId;

          this.findById(trackId);
          this.findEByTrackId(trackId);


          this.Texhandle.trackId= trackId;
        },

        handleSelectionChange(){

        },
        /*findProgresstype(){
          this.$http({
            method: "GET",
            url: "http://localhost:8090/tExbrief/type",
          }).then(resp => {
            console.log(resp);
            this.exbrief.progresses = resp.data.data.records;
            console.log(this.liableside);
          })
        },*/
        findtype(){
          this.$http({
            method: "GET",
            url: "http://localhost:8090/tExhandle/type",
          }).then(resp => {
            console.log(resp);
            this.liableside = resp.data.data.records;
            console.log(this.liableside);
          })
        },
        // 页面大小的触发函数
        handleSizeChange(val) {

          //拿到当前的页面大小
          this.pageSize = val;
          //重新加载 数据
          this.findAll(this.currentPage, this.pageSize);
        },
        //当前页面变化触发的函数
        handleCurrentChange(val) {

          this.currentPage = val;
          // 当前第几页发生了变化  重新加载数据
          this.findAll(this.currentPage, this.pageSize);
        },
        //查询数据
        findAll(currentPage, pageSize,exceptionId,dispatchId,exceptionType) {

        /*  if (exceptionId || dispatchId || exceptionType){   //   ||逻辑或，解决如果在第二个页面，就不能查询的问题
            currentPage = 1;
            this.currentPage = 1;
          }*/
          console.log(currentPage);
          console.log(pageSize);
          console.log(exceptionId);
          console.log(dispatchId);
          console.log(exceptionType);
          this.$http({
            method: "GET",
            url: "http://localhost:8090/tExbrief",
            params: {
              currentPage: currentPage,
              pageSize: pageSize,
              exceptionId:exceptionId,
              dispatchId:dispatchId,
              exceptionType:exceptionType
            }
          }).then(resp => {
            // this.houses = resp.data.data.data; // 拿到服务器的 回写数据中的data数据的对象中data数据
            console.log(resp);
            console.log(resp.data.data.data);
            this.exbriefs = resp.data.data.data;
            this.total = resp.data.data.total;
          })
        },
      },
      created() {
        this.findAll(1, 2);
        this.findtype();
        /*this.findProgresstype();*/
      },
    }
</script>

<style scoped>

</style>
